package music.utils.dbcp;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class OracleDBCP {

    // 자바에서 사용할 자원을 디렉토리경로 표기식으로 정의
    // JDK 경로  c:/Java/JDK1.8.20
    private static String jndi = "java:/comp/env";
    private static String oracle11dbcp = "jdbc/oracle11xe";
    private static String USR = "";
    private static String PWD = "";

    public static Connection openDBCP() throws Exception {
        Context initCtx = new InitialContext();
        Context envCtx = (Context) initCtx.lookup(jndi);
        DataSource ds = (DataSource) envCtx.lookup(oracle11dbcp);
        return ds.getConnection();
    }

    public static void closeDBCP(Connection c, PreparedStatement p, ResultSet r) {
        if(r != null) try{r.close();}catch(Exception e){}
        if(p != null) try{p.close();}catch(Exception e){}
        if(c != null) try{c.close();}catch(Exception e){}


    }
}
